package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.constant.AppendixType;
import org.jsola.contract.constant.FileType;
import org.jsola.contract.constant.SignMethod;
import org.jsola.contract.constant.SignOrder;
import org.jsola.contract.constant.SignType;
import org.jsola.contract.dto.CategoryAddDTO;
import org.jsola.contract.dto.CategoryUpdateDTO;
import org.jsola.contract.entity.CategoryDO;
import org.jsola.contract.query.CategoryQuery;
import org.jsola.contract.service.ICategoryService;
import org.jsola.contract.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 合同类型
 *
 * @author JanusMix
 */
@Component
public class CategoryTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICategoryService categoryService;

    /**
     * 生成add测试数据
     * @return CategoryAddDTO
     */
    public CategoryAddDTO getCategoryAddDTO(){
        CategoryAddDTO categoryAddDTO = new CategoryAddDTO();
        categoryAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        categoryAddDTO.setIsSiteUpdate(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        categoryAddDTO.setGroupId(SafeKit.getLong(getRandomValue("bigint",11)));
        categoryAddDTO.setSourceId(getRandomValue("varchar",32));
        categoryAddDTO.setSubjectId(getRandomValue("varchar",32));
        categoryAddDTO.setName(getRandomValue("varchar",255));
        categoryAddDTO.setDescription(getRandomValue("varchar",1000));
        categoryAddDTO.setRemark(getRandomValue("varchar",500));
        categoryAddDTO.setEnterpriseSealId(SafeKit.getLong(getRandomValue("bigint",11)));
        categoryAddDTO.setSignType(SignMethod.BOTH.getValue());
        categoryAddDTO.setSignSealType(SignType.PERSON.getValue());
        categoryAddDTO.setExpireDays(SafeKit.getInteger(getRandomValue("int",11)));
        categoryAddDTO.setSignOrder(SignOrder.NONE.getValue());
        categoryAddDTO.setFileType(FileType.LABORCONTRACTLIMIT.getValue());
        categoryAddDTO.setAppendixType(AppendixType.PERSONALCARD.getValue());
        categoryAddDTO.setIssue(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return categoryAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CategoryUpdateDTO
     */
    public CategoryUpdateDTO getCategoryUpdateDTO(CategoryVO categoryVO){
        return categoryService.selectDOById(categoryVO.getId(), SITE_ID).to(CategoryUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CategoryQuery
     */
    public CategoryQuery getCategoryQuery() {
        CategoryQuery categoryQuery = new CategoryQuery();
        List<CategoryDO> categoryDOList = categoryService.list(new CategoryDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(categoryDOList)) {
            CategoryDO categoryDO = categoryDOList.get(0);
            categoryQuery = categoryDO.to(CategoryQuery.class);
        }
        return categoryQuery;
    }

    /**
     * 保存示例
     * @return CategoryVO
     */
    public CategoryVO saveCategoryExample(){
        CategoryAddDTO addDTO = this.getCategoryAddDTO();
        CategoryVO categoryVO = categoryService.save(addDTO,buildTokenUser());
        return categoryVO;
    }


}

